from pathlib import Path

class GrubThemeBuilder:
    def __init__(self, icon_dir, animation_script):
        self.icon_dir = Path(icon_dir)
        self.script = animation_script

    def build_theme(self, output_dir):
        theme_dir = Path(output_dir) / "custom_theme"
        theme_dir.mkdir(exist_ok=True)

        # 生成 theme.txt
        with open(theme_dir / "theme.txt", "w") as f:
            f.write(self._generate_theme_config())

        # 拷贝图标资源
        for icon_file in self.icon_dir.glob("*.png"):
            shutil.copy(icon_file, theme_dir)

        # 拷贝脚本资源
        with open(theme_dir / "animation.lua", "w") as f:
            f.write(self.script)

    def _generate_theme_config(self):
        return """
if background_image then
    desktop_image = background_image
end

menuentry_style = {
    font = "DejaVu",
    text_color = "#ffffff",
    hover_color = "#ffcc00",
    selected_color = "#0099cc"
}
"""